import java.io.PrintStream;
import java.util.Vector;
import java.util.ListIterator;

/**
 * Class containing the main details for an enterprise offering Office Services.
 * @author  Tom Crowe (09137149@ucdconnect.ie)
 */
public class Office {

	public static final String PRINTING = "Printing";
	public static final String PHOTOCOPY = "Photocoping";
	public static final String OFFICE_SUPPLIES = "Office Supplies";
	public static final String PHOTO_PRINT = "Photo Printing";
	public static final String INTERNET = "Internet Access";
	public static final String LEAFLETS_FLYERS = "Leaflets and Flyers";
	public static final String LOGO_DESIGN = "Logo Design";
	public static final String LARGE_FORMAT_AND_POSTERS = "Large Format and Posters";
	public static final String STATIONERY = "Stationery";
	public static final String PROMOTIONAL_PRODUCTS = "Promotional Products";
	public static final String CORPORATE_CHRISTMAS_CARDS = "Corporate Christmas Cards";
	
	
	//Message parsers can expect this number of fields for Main Office Info
  public static final int NUM_MANDATORY_FIELDS = 5; 
	
  // Access is through the getters/setters
	private int m_Ref = 0;				/* Mandatory */
	private String m_Name;				/* Mandatory */
	private String m_Location;		/* Mandatory */
	private String m_Phone;				/* Mandatory */
	private String m_Email;				/* Mandatory */
	private String m_MapFile;
	private Vector<String> m_OffServices;

	
	/**
	 * Constructor with full attribute set for class
	 * @param ref Unique reference to Office
	 * @param name Name of Office Services enterprise
	 * @param location Textual description of Enterprise location
	 * @param phone Main phone number
	 * @param email Main enterprise email address
	 * @param mapFile Map file showing exact location
	 */
	public Office(int ref, String name, String location, String phone, String email, String mapFile){
		m_Ref = ref;
		m_Name = name;
		m_Location = location;
		m_Phone = phone;
		m_Email = email;
		m_MapFile = mapFile;
		m_OffServices = new Vector<String>();
	}

	
	/**
	 * Constructor with all attributes except Map
	 * @param ref Unique reference to Office
	 * @param name Name of Office Services enterprise
	 * @param location Textual description of Enterprise location
	 * @param phone Main phone number
	 * @param email Main enterprise email address
	 */
	public Office(int ref, String name, String location, String phone, String email){
		m_Ref = ref;
		m_Name = name;
		m_Location = location;
		m_Phone = phone;
		m_Email = email;
		m_OffServices = new Vector<String>();
	}

	
	/**
	 * Assembles and returns the main office info as a delimited string, useful for 
	 * inclusion in a fixed format delimited message protocol. Synchronised in case
	 * of a clash with a field update while constructing the delimited string.
	 * @param delim The delimiting character between Office fields in the return string.
	 * @return Delimited string of Office information
	 */
	synchronized public String getMainInfoAsDelimString(String delim){
		StringBuilder draftResp = new StringBuilder();
		draftResp.append(m_Ref + delim);
		draftResp.append(m_Name + delim);
		draftResp.append(m_Location + delim);

		if (m_Phone != null)
			draftResp.append(m_Phone + delim);
		else
			draftResp.append('\u0020' + delim);

		if (m_Email != null)
			draftResp.append(m_Email + delim);
		else
			draftResp.append('\u0020' + delim);
		
		return draftResp.toString();
	}
	
	/**
	 * Accessor method for getting unique Office id
	 * @return Unique office id
	 */
	public int getRef (){
		return m_Ref;
	}
	
	/**
	 * Accessor method for getting Enterprise name
	 * @return Enterprise name
	 */
	public String getName(){
		return m_Name;
	}
	
	/**
	 * Accessor method for getting Location text
	 * @return Location Text
	 */
	public String getLocation(){
		return m_Location;
	}
	
	/**
	 * Accessor method for getting Phone number
	 * @return Phone number
	 */
	public String getPhone(){
		return m_Phone;
	}
	
	/**
	 * Accessor method for getting email 
	 * @return Email address
	 */
	public String getEmail(){
		return m_Email;
	}
	
	/** 
	 * Accessor method for getting list of Office services
	 * @return List of Office services
	 */
	public Vector<String> getOffServices(){
		return m_OffServices;
	}

	/**
	 * Accessor method for adding a service to an office
	 * @param srvc Service to be added
	 */
  public void addOfficeService(String srvc){
  	m_OffServices.add(srvc);
  }

  /**
   * Assembles and returns the list of Office services as a delimited string, useful for
	 * inclusion in a fixed format delimited message protocol. Synchronised in case
	 * of a clash with a field update while constructing the delimited string.
	 * @param delim The delimiting character between Office fields in the return string.
	 * @return Delimited string of Office information
	 */
  synchronized public String getOffServicesDelimString(String delim){
  	StringBuilder draftResp = new StringBuilder();
  	ListIterator<String> iter = m_OffServices.listIterator();
  	
  	while (iter.hasNext())
  		draftResp.append(iter.next() + delim);
  	
  	return draftResp.toString();
  }

  /**
   * Print the main Office info to the console
   */
	public void printMainInfoToConsole() {
		PrintStream out = System.out;
		
		out.println();
		out.println("\t Office Reference: " + m_Ref + ",\t Name: " + m_Name);
		out.println("\t\t Location: " + m_Location);
		out.println("\t\t Phone: " + m_Phone);
		out.println("\t\t Email: " + m_Email);
		out.println();
	}
} // End of class


